---
title: "Linux LVM"
categories:
- linux
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org7a9a236">Intro</a></li>
<li><a href="#org97cbdab">命令</a>
<ul>
<li><a href="#org9b565a6">PV</a></li>
<li><a href="#org4bdb7a3">VG</a></li>
<li><a href="#org12a52ca">LV</a></li>
<li><a href="#org379dc3f">Others</a></li>
<li><a href="#orgf11bb94">FQA</a>
<ul>
<li><a href="#org80516b2">lvextends 之后 df 看到的还是原来的大小</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org7a9a236">
<h2 id="org7a9a236">Intro</h2>
<div class="outline-text-2" id="text-org7a9a236">
<blockquote>
<p>
<a href="https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open">https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open</a>
</p>
</blockquote>
<p>
LVM利用Linux内核的device-mapper来实现存储系统的虚拟化（系统分区独立于底层硬件）。
LVM的基本组成块（building blocks）如下： 
</p>
<ul class="org-ul">
<li>PV(physical volume)即物理卷,就是物理磁盘,可以通过fdisk -l 查看操作系统有几块硬盘，/dev/sda、/dev/sdb等</li>
<li>VG(volume group)即卷组,就是一组物理磁盘的组合,里面可以有一块硬盘也可以有多块硬盘</li>
<li>LV(logical volume)及逻辑卷,就是在VG(指定的物理磁盘组)里面划分出来的</li>
</ul>
<p>
LVM的作用，简言之，就是：将多个PV组合成一个VG，然后在VG上划分LV。
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org97cbdab">
<h2 id="org97cbdab">命令</h2>
<div class="outline-text-2" id="text-org97cbdab">
</div>
<div class="outline-3" id="outline-container-org9b565a6">
<h3 id="org9b565a6">PV</h3>
<div class="outline-text-3" id="text-org9b565a6">
<ul class="org-ul">
<li>pvcreate :根据物理盘,创建pv</li>
<li>pvscan :查询目前系统里的pv</li>
<li>pvdisplay:显示pv的状态</li>
<li>pvremove:将pv属性移除</li>
</ul>
</div>
</div>
<div class="outline-3" id="outline-container-org4bdb7a3">
<h3 id="org4bdb7a3">VG</h3>
<div class="outline-text-3" id="text-org4bdb7a3">
<ul class="org-ul">
<li>vgcreate:创建vg</li>
<li>vgscan:查找当前系统里面的vg</li>
<li>vgdisplay:显示当前系统vg的状态</li>
<li>vgextend:给vg添加额外的pv</li>
<li>vgreduce:在vg内删除pv</li>
<li>vgchange:设置vg是否是启动状态(active)</li>
<li>vgremove:删除一个vg</li>
</ul>
</div>
</div>
<div class="outline-3" id="outline-container-org12a52ca">
<h3 id="org12a52ca">LV</h3>
<div class="outline-text-3" id="text-org12a52ca">
<ul class="org-ul">
<li>lvcreate:创建lv</li>
<li>lvscan:查询当前系统的lv</li>
<li>lvdisplay:显示lv的属性</li>
<li>lvextend:给lv添加容量</li>
<li>lvredurce:给lv减少容量</li>
<li>lvremove:删除一个lv</li>
<li>lvresize:对lv大小的容量进行调整</li>
</ul>
</div>
</div>
<div class="outline-3" id="outline-container-org379dc3f">
<h3 id="org379dc3f">Others</h3>
<div class="outline-text-3" id="text-org379dc3f">
<ul class="org-ul">
<li>sudo lsblk 能够查看磁盘树形图</li>
<li>sudo parted /dev/sda print 查看磁盘分区，逻辑分区，主分区等信息</li>
<li>xfs_growfs /dev/centos/root lvextend扩容之后使用这个命令，扩容才生效[1]</li>
</ul>
</div>
</div>
<div class="outline-3" id="outline-container-orgf11bb94">
<h3 id="orgf11bb94">FQA</h3>
<div class="outline-text-3" id="text-orgf11bb94">
</div>
<div class="outline-4" id="outline-container-org80516b2">
<h4 id="org80516b2">lvextends 之后 df 看到的还是原来的大小</h4>
<div class="outline-text-4" id="text-org80516b2">
<blockquote>
<p>
<a href="https://www.linuxtechi.com/extend-lvm-partitions/">https://www.linuxtechi.com/extend-lvm-partitions/</a>
<a href="https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open">https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open</a>
</p>
</blockquote>
<p>
Run the resize2fs command.
CentOS 7 equire xfs_growfs rather than resize2fs
</p>
<pre class="example">
xfs_growfs /dev/centos/root
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
